import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { rmSync } from 'node:fs'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import electron from 'vite-plugin-electron'
import renderer from 'vite-plugin-electron-renderer'
import path from 'path'




// https://vitejs.dev/config/
export default defineConfig(() => {
  rmSync('dist-electron', { recursive: true, force: true })
  return {
    plugins: [
      vue(),
      electron(
        [
          {
            entry: "electron/main/index.ts",
            vite: {
              build: {
                outDir: 'dist-electron/main'
              }
            }
          }, {
            entry: "electron/preload/index.ts",
            vite: {
              build: {
                outDir: 'dist-electron/preload'
              }
            }
          }
        ]
      ),
      renderer({
        nodeIntegration: true
      }),
      AutoImport({
        resolvers: [ElementPlusResolver()]
      }),
      Components({
        resolvers: [ElementPlusResolver()]
      })
    ],
    server: {
      port: 8080
    },
    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'src')
      }
    },
  }
})
